// AboutDlg.cpp : implementation of the CGroupsDlg class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#ifdef WIN32_PLATFORM_PSPC
#include "resourceppc.h"
#else
#include "resourcesp.h"
#endif
#include "newnamedlg.h"
#include "utils.h"

static const int MAX_NAME_EDIT_TEXT = 64;

LRESULT CNewNameDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
    AtlCreateMenuBar(m_hWnd, IDM_NEXT_CANCEL);

#ifdef WIN32_PLATFORM_WFSP
    if (hMenuBar != NULL)
        AtlActivateBackKey(hMenuBar);
#endif

    m_NameEdit.Attach(GetDlgItem(IDC_EDT_NAME));
    m_NameEdit.SetFocus();

    m_NameEdit.LimitText(MAX_NAME_EDIT_TEXT);

    UpdateUI();

    return bHandled = FALSE;
}

LRESULT CNewNameDlg::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
    m_SelectedListItem = 1; // m_List.GetSelectedIndex();
    m_NameEdit.GetWindowText(m_Name);

    m_NameEdit.Detach();

    return bHandled = FALSE;
}

LRESULT CNewNameDlg::OnMenuNext(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    StdCloseDialog(ID_MENU_NEXT);
    return 0;
}

LRESULT CNewNameDlg::OnMenuCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    StdCloseDialog(ID_MENU_CANCEL);
    return 0;
}

LRESULT CNewNameDlg::OnEdtNameChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    UpdateUI();
    return 0;
}

void CNewNameDlg::UpdateUI(void)
{
    Utils::EnableMenuItem(
        this->m_hWnd,
        ID_MENU_NEXT,
        m_NameEdit.GetWindowTextLength() == 0 ? false : true);
}
